/**
 * Created by Administrator on 2017/4/18.
 */
var React = require('react');


var Bheader = require('../widget/Bheader');
var Footer = require('../widget/Footer');
var postAjax = require('../tools/postAjax');
var ServerIP = require('../tools/ServerIP');
var MsgBox = require('../components/MsgBox');
var Icon = require('../components/Icon');

module.exports = React.createClass({
    getInitialState: function () {
        return {
            theme:"Default", //Default/Blue
            LoginAccount:"",
            loginFlag:false,//登录信息是否输入
        }
    },

    componentDidMount: function () {

    },

    action(e){
        var action = e.currentTarget.getAttribute("action");
        location.href = action;
    },

    login:function(e){
        var p =this;
        var LoginAccount = this.refs.LoginAccount.value;
        var LoginPassword = this.refs.LoginPassword.value;
        postAjax("POST",ServerIP.ip+"/kLoginController.do?login",{
            account:LoginAccount,
            password:LoginPassword
        },function (dt) {
            if (dt && dt.attributes.result == "true") {
                localStorage.shopId = dt.attributes.shopid;
                localStorage.setItem("userId",dt.attributes.userId);
                location.href = "#wode";
            }else{
                if(dt.msg){
                    p.refs.MsgBox.setState({
                        type: "no",
                        timeout:3000,
                        show:true,
                        word:dt.msg
                    });
                }
            }
        })
    },

    changed(){
        var LoginAccount = this.refs.LoginAccount.value;
        var LoginPassword = this.refs.LoginPassword.value;
        this.setState({LoginAccount:LoginAccount});
        if(LoginAccount&&LoginPassword){
            this.setState({loginFlag:true})
        }else{
            this.setState({loginFlag:false})
        }
    },

    render: function () {
        var p = this;
        return (
            <div className="main"  id="main">
                <Bheader theme={this.state.theme} title="登录" headr="false" hact="#wode" wordBtn="注册"></Bheader>
                <div className="container-t">
                    <ul className="register">
                        <li>
                            <Icon className="loginIcon" icon="#icon-wode" />
                            <input ref="LoginAccount" type="text" onChange={this.changed} placeholder="请输入您的帐号" />
                        </li>
                        <li>
                            <Icon className="loginIcon" icon="#icon-mima" />
                            <input ref="LoginPassword" type="password"  onChange={this.changed} placeholder="请输入您的密码" />
                        </li>
                    </ul>
                    <div className={this.state.loginFlag?"registerBtn clicked":"registerBtn"} onClick={this.login}>
                        登录
                    </div>
                    <div className="accpass_login"  onClick={this.action} action="#login">
                        <span>手机号码登录</span>
                    </div>
                </div>
                <MsgBox ref="MsgBox"></MsgBox>
            </div>
        )
    }
});